
const entryHandler = (list) => {
    if(observer) {
        observer.disconnect();
    }
    for (const entry of list.getEntries()) {
            const json = entry.toJSON();
            const reportData = {
                ...json,
                type: 'performance',
                subType: entry.name,
                pageUrl: window.location.href
            }
            // 上报数据
            console.log('reportData', reportData);
    }
}


// 统计和计算LCP的时间
const observer = new PerformanceObserver(entryHandler);
// buffered: true 确保观察到所有的paint事件
observer.observe({ type: 'largest-contentful-paint', buffered: true });